package com.yanjr.modules.cms.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.yanjr.common.Constants;
import com.yanjr.common.persistence.BaseDaoImpl;
import com.yanjr.common.utils.StringUtils;
import com.yanjr.modules.cms.dao.CategoryDao;
import com.yanjr.modules.cms.entity.Category;

@Repository("categoryDao")
public class CategoryDaoImpl extends BaseDaoImpl<Category> implements CategoryDao {

	@Override
	public List<Category> findByParentIdsLike(String parentIds) {
		String sql = "select * from cms_category where parent_ids like ?";
		return super.findList(sql, new Object[] {parentIds});
	}

	@Override
	public List<Category> findByModule(String module) {
		String sql = "select * from cms_category where del_flag=? and (module='' or module=?) order by site_id, sort";
		return super.findList(sql, new Object[] {Constants.DEL_FLAG_NORMAL, module});
	}

	@Override
	public List<Category> findByParentId(String parentId, String isMenu) {
		String sql = "select * from cms_category where del_flag=? and parent_id=? and in_menu=? order by site_id, sort";
		return super.findList(sql, new Object[] {Constants.DEL_FLAG_NORMAL, parentId, isMenu});
	}

	@Override
	public List<Category> findByParentIdAndSiteId(String parentId, String siteId) {
		String sql = "select * from cms_category where del_flag=? and parent_id=? and site_id=? order by site_id, sort";
		return super.findList(sql, new Object[] {Constants.DEL_FLAG_NORMAL, parentId, siteId});
	}

	@Override
	public List<Category> findByIdIn(String[] ids) {
		String sql = "select * from cms_category where id in ('" + StringUtils.join(ids, "','") + "')";
		return super.findList(sql);
	}

}
